//
//  YHEmotionPopView.swift
//  EmotionKeyboard
//
//  Created by 昱含 on 16/6/1.
//  Copyright © 2016年 YuHan. All rights reserved.
//

import UIKit

class YHEmotionPopView: UIView {

    @IBOutlet weak var emotionBtn: YHEmotionButton!
    
    class func loadPopView() -> YHEmotionPopView {
        let pop = NSBundle.mainBundle().loadNibNamed("YHEmotionPopView", owner: nil, options: nil).last as! YHEmotionPopView
        return pop
        
    }
    
    func show(btn: YHEmotionButton){
        let window = UIApplication.sharedApplication().windows.last!
        if self.superview == nil {
            
            window.addSubview(self)
        }
        self.hidden = false
        let rect = btn.superview!.convertRect(btn.frame, toView: window)
        center.x = CGRectGetMidX(rect)
        frame.origin.y = CGRectGetMaxY(rect) - bounds.height
       emotionBtn.emotion = btn.emotion
    }
    
    func dismissAfter() {
        let time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(Double(NSEC_PER_SEC) * 0.2))
        dispatch_after(time_t, dispatch_get_main_queue()) {
//            self.hidden = true
//            self.removeFromSuperview()
            self.hidden = true
        }
    }


}
